rm(list=ls(all=TRUE))

library(dplyr)
library(ggplot2)
library(stringr)
library(lubridate)
library(haven)

# Load data
d <- read_dta("newspaper.dta")

# calculate yearly rates of mentions
yearly_rates_quru <- d$amount/d$total

# plot Figure 2
perc_year_guochi <- ggplot(data=d, aes(x = month, y = yearly_rates_quru, color = "media_type")) +
  geom_point() +
  scale_x_date(breaks = "2 year", date_labels = "%Y") +
  geom_line() + 
  labs(y = "Percentage of Mentions",
       x = "Date") + 
  theme_bw() +
  theme(text = element_text(family = "STKaiti"),
        legend.position = "none", 
        axis.text.x = element_text(angle = 90, hjust = 1),
        strip.text.x = element_text(size =240, face="bold"),
        axis.text=element_text(size=18),
        axis.title=element_text(size=20,face="bold"),
        axis.title.x = element_text(size = 20),
        plot.title = element_text(size = 25, face = "bold"))

perc_year_guochi
ggsave(paste0(getwd(), "/graphs/perc_year46_15_guochi.png"), perc_year_guochi, width = 12, height = 9)
